package com.campus.handler;


import com.campus.response.Code;
import com.campus.response.ResponseResult;
import com.campus.response.ResultCode;
import io.swagger.v3.core.util.Json;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Objects;



@Component
@Slf4j
public class AuthenticationHandle implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException{
        response.setContentType("application/json;charset=UTF-8");
        log.error("过滤器出现错误：{}",authException.getMessage(),authException);
        ResponseResult<Object> responseResult=new ResponseResult<>(ResultCode.NO_LOGIN,null);
        response.getWriter().write(Json.pretty(responseResult));

    }
}
